February 6, 2017
options(digits=22) 1.1 - 0.2
options(digits=22) 1.1 - 0.2
## [1] 0.9000000000000001332268
options(digits=22) 1.1 - 0.2
## [1] 0.9000000000000001332268
Reason: Machine representation of float (numbers with decimal points)
all(c()) any(c())
any(c())
## [1] FALSE
all(c())
## [1] TRUE
Solution in the help file:
dat <- data.frame(measure = c('6','1', '1', '1', '2','10','4'))
as.numeric(dat$measure)
## [1] 5 1 1 1 3 2 4
str(dat$measure)
## Factor w/ 5 levels "1","10","2","4",..: 5 1 1 1 3 2 4
dat$measure
## [1] 6 1 1 1 2 10 4 ## Levels: 1 10 2 4 6
c(dat$measure, c(22, 1))
## [1] 5 1 1 1 3 2 4 22 1
require('bananas')
library('bananas')
require('bananas')
## Loading required package: bananas
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE, ## logical.return = TRUE, : there is no package called 'bananas'
library('banana')
## Error in library("banana"): there is no package called 'banana'
=> Use library in most cases
x <- require('bananas')
x
## [1] FALSE
if(!x){
install.packages('banana')
}
x <- 1 x = 1
What's the difference?
In practice same functionality.
mean(new_var <- c(1,2))
## [1] 1.5
new_var
## [1] 1 2
var = 1
fun = function(x){var <<- x}
fun(2)
var
## [1] 2